package com.example.yls.demoa;

import android.os.Handler;
import android.os.Message;
import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.ArrayAdapter;
import android.widget.ListView;

import java.util.ArrayList;

import jp.co.recruit_lifestyle.android.widget.WaveSwipeRefreshLayout;
import uk.co.imallan.jellyrefresh.JellyRefreshLayout;
import uk.co.imallan.jellyrefresh.PullToRefreshLayout;

public class WaveActivity extends AppCompatActivity {
    private ListView mylistView;
    private WaveSwipeRefreshLayout swipeRefreshLayout;
    private ArrayList<String> arrayList=new ArrayList<>();
    private ArrayAdapter<String> arrayAdapter;
    private Handler handler;
    private  final int  SEND_REFRENSH =1001;
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_wave);


        initView();
         swipeRefreshLayout.setOnRefreshListener(new WaveSwipeRefreshLayout.OnRefreshListener() {
             @Override
             public void onRefresh() {
                 new Thread(new Runnable() {
                     @Override
                     public void run() {
                         arrayList.clear();
                         try {
                             Thread.sleep(3000);
                         } catch (InterruptedException e) {
                             e.printStackTrace();
                         }

                         for(int i=0;i<10;i++){
                             arrayList.add("下拉刷新+"+i);

                         }
                         handler.sendEmptyMessage(SEND_REFRENSH);

                     }
                 }).start();
             }
         });

    }

    private void initView() {
        swipeRefreshLayout=findViewById(R.id.swipeLayout);
        mylistView=findViewById(R.id.mylist);
        arrayAdapter=new ArrayAdapter<String>(WaveActivity.this,android.R.layout.simple_expandable_list_item_1,arrayList);
        mylistView.setAdapter(arrayAdapter);
        handler=new Handler(new Handler.Callback() {
            @Override
            public boolean handleMessage(Message message) {

                if (message.what==SEND_REFRENSH){
                    arrayAdapter.notifyDataSetChanged();
                    swipeRefreshLayout.setRefreshing(false);
                }


                return false;
            }
        });

    }
}
